<gm:page title="Admin" authenticate="true">
  
  <script type="text/javascript">
    <![CDATA[
      function getLatLngs(listID)
      {
        var geocoder = new GClientGeocoder();
        var listData = google.mashups.getObjectById(listID).getData();
    
        var contentGPath = new GPath("atom:content");
        var longGPath = new GPath("gd:long");
        var latGPath = new GPath("gd:lat");
        
        for (var i=0; i<listData.size(); i++)
        {
          var entry = listData.entryAt(i);
        
          if (latGPath.getValue(entry) != undefined)
            continue;
        
          listData.removeEntry(entry);
        
          geocoder.getLatLng(contentGPath.getValue(entry),
            function(point) {
              if (point) {
                longGPath.setValue(entry, point.lng().toString());
                latGPath.setValue(entry, point.lat().toString());
                listData.addEntry(entry);
              }
              else {
                alert("No point");
              }
            }
          );
        }
      }
    ]]>
  </script>
  
  <h1 style="text-align:center">Rhode Island State Parks</h1>
  <div align="center">
    <input type="button" value="Get lat/lng values" onclick="getLatLngs('RIParkList')" />
  </div>
  <gm:list id="RIParkList" data="${app}/RIParks" template="parksTemplate" />
  <p></p>
  
  <h1 style="text-align:center">California State Parks</h1>
    <gm:list id="CAParkList" data="${app}/CAParks" template="parksTemplate" />
  <p></p>
  
  <gm:template id="parksTemplate">
    <div align="center">
      <gm:create label="Create park" />
    </div>
    <p></p>
    <table border="1" width="100%">
      <th>Park name</th>
      <th>Address</th>
      <th>Lat</th>
      <th>Lng</th>
      <tr repeat="true">
        <td width="35%"><gm:text ref="atom:title" /></td>
        <td width="35%"><gm:text ref="atom:content" /></td>
        <td width="10%"><gm:text ref="gd:lat" /></td>
        <td width="10%"><gm:text ref="gd:long" /></td>
        <td width="10%"><gm:editButtons /></td>
      </tr>
    </table>
  </gm:template>

</gm:page>